<%-- 
    Document   : billmasterdb
    Created on : Jan 14, 2013, 10:39:38 PM
    Author     : Bittuji
--%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.util.Date"%>
<%@include  file="db.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
        
        String billno = request.getParameter("billno");
        int crdays = Integer.parseInt(request.getParameter("crdays"));
        
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        Date rdate = format.parse(request.getParameter("date"));
        java.sql.Date date = new java.sql.Date(rdate.getTime());
        
       
        String tid = request.getParameter("tid");
        String prname = request.getParameter("prname");
        String ptid = request.getParameter("ptid");
        String disctype = request.getParameter("disctype");
        int qty = Integer.parseInt(request.getParameter("qty"));
        float disc = Float.parseFloat(request.getParameter("disc"));
        float amt = Float.parseFloat(request.getParameter("amt"));
        float vat = Float.parseFloat(request.getParameter("vat"));
        float total = Float.parseFloat(request.getParameter("total"));
        
        String sql = "INSERT INTO `bill_master`(`id`, `bill_no`, `date`, `cr_day`, `tran_id`, `pr_name`, `pt_id`, `quantity`, `disc_type`, `disc`, `amount`, `vat`, `total_amt`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
        PreparedStatement pstmt = con.prepareStatement(sql);
        
        pstmt.setNull(1, java.sql.Types.INTEGER);
        pstmt.setString(2, billno);
        pstmt.setDate(3, date);
        pstmt.setInt(4, crdays);
        pstmt.setString(5, tid);
        pstmt.setString(6, prname);
        pstmt.setString(7, ptid);
        pstmt.setInt(8, qty);
        pstmt.setString(9, disctype);
        pstmt.setFloat(10, disc);
        pstmt.setFloat(11, amt);
        pstmt.setFloat(12, vat);
        pstmt.setFloat(13, total);
        
        int result = pstmt.executeUpdate();
        
        if(result==1)
            System.out.println("data inserted");
        
        String sql1 = "INSERT INTO `sales_entry`(`date`, `party_name`, `product_id`, `quantity`, `billno`, `total_amount`, `transport_name`) VALUES (?,?,?,?,?,?,?)";
        
        PreparedStatement pst = con.prepareStatement(sql1);
        
        pst.setDate(1, date);
        pst.setString(2, prname);
        pst.setString(3, ptid);
        pst.setInt(4, qty);
        pst.setString(5, billno);
        pst.setFloat(6, total);
        pst.setString(7, ptid);
        
        int result1 = pst.executeUpdate();
        
        %>
        
    </body>
</html>
